package com.flyou.ccnucenter.ui.activity;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.google.gson.Gson;
import com.umeng.analytics.MobclickAgent;

import org.simple.eventbus.EventBus;

import java.io.File;
import java.lang.reflect.Type;


public  abstract class BaseActivity1 extends AppCompatActivity {
public ProgressDialog mProgressDialog;
    private  Bundle savedInstanceState;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        MobclickAgent.onResume(this);
        super.onCreate(savedInstanceState);
        this.savedInstanceState=savedInstanceState;
        EventBus.getDefault().register(this);
        initView();
        initDate();
        setListener();

    }
//初始化view
    protected abstract void initView();
//初始化date
    protected abstract void initDate();
//设置adapter
    protected abstract void setListener();


    @Override
    protected void onDestroy() {
        MobclickAgent.onPause(this);
        EventBus.getDefault().register(this);
        super.onDestroy();
    }

    @Override
    protected void onResume() {
        super.onResume();

    }
    public static void shareMsgBySystem(Context context, String activityTitle, String msgTitle, String msgText,
                                String imgPath) {
        Intent intent = new Intent(Intent.ACTION_SEND);
        if (imgPath == null || imgPath.equals("")) {
            intent.setType("text/plain"); // 纯文本
        } else {
            File f = new File(imgPath);
            if (f != null && f.exists() && f.isFile()) {
                intent.setType("image/png");
                Uri u = Uri.fromFile(f);
                intent.putExtra(Intent.EXTRA_STREAM, u);
            }
        }
        intent.putExtra(Intent.EXTRA_SUBJECT, msgTitle);
        intent.putExtra(Intent.EXTRA_TEXT, msgText);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(Intent.createChooser(intent, activityTitle));
    }
    /*
   * 对象转 json
   * obj 对象
   * */
    public String toJson(Object obj) {

        Gson gson = new Gson();
        return gson.toJson(obj);
    }

    /*
    * json转对象
    * classOfT 对象类型
    * */
    public <T> T toObj(String json, Type typeOfT) {
        Gson gson = new Gson();
        T t = gson.fromJson(json, typeOfT);
        return t;
    }
public Bundle getSavedInstanceState(){

    return savedInstanceState;
}
}
